<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="评价人真名、账号、商品名、内容" clearable style="width: 280px"></el-input>
      </el-form-item>
      <el-form-item label="">
		<el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
		</el-date-picker>
	  </el-form-item>
	  <el-form-item label="">
		<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
		</el-date-picker>
	  </el-form-item>
      <el-form-item label="审核状态">
		<el-select v-model="dataForm.auditStatus" placeholder="审核状态">
		  <el-option label="全部" value="" ></el-option>
		  <el-option label="待审核" value="0" ></el-option>
          <el-option label="审核通过" value="1" ></el-option>
          <el-option label="审核拒绝" value="2" ></el-option>
		</el-select>
	  </el-form-item>
    <el-form-item label="来源">
      <el-select v-model="dataForm.commentSrc" placeholder="来源">
		    <el-option label="全部" value="" ></el-option>
		    <el-option label="送贝" value="0" ></el-option>
        <el-option label="淘宝" value="1" ></el-option>
		</el-select>
    </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="
          dataForm.keywords = ''
          dataForm.startTime = ''
          dataForm.endTime = ''
          dataForm.auditStatus = ''
          dataForm.starClass = ''
          getDataList()">重置</el-button>
        <!-- <el-form-item label="批量审核">
		<el-select v-model="dataForm.auditType" placeholder="审核状态">
          <el-option label="审核通过" value="1" ></el-option>
          <el-option label="审核拒绝" value="2" ></el-option>
		</el-select>
	  </el-form-item> -->
        <el-button type="success" @click="adopt(1)" :disabled="dataListSelections.length <= 0">批量审核通过</el-button>
        <el-button type="danger" @click="adopt(2)" :disabled="dataListSelections.length <= 0">批量审核拒绝</el-button>
        <!-- <el-button v-if="isAuth('goods:shoppinggoods:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('goods:shoppinggoods:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="评论时间">
      </el-table-column>
      <el-table-column
        prop="realName"
        header-align="center"
        align="center"
        label="评论人真名">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="评论人账号"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="commentSrc"
        header-align="center"
        align="center"
        label="评论来源"
        width="100px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.commentSrc == 0" type="success">送贝</el-tag>
          <el-tag v-if="scope.row.commentSrc == 1" type="success">淘宝</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="rate"
        header-align="center"
        align="center"
        label="评价等级"
        width="145px">
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.overallEvaluationLevel"
            :colors="colors">
          </el-rate>
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="consistentLevel"
      </el-table-column>
      <el-table-column
        prop="consistentLevel"
        header-align="center"
        align="center"
        label="整体评价"
        width="145px">
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.consistentLevel"
            :colors="colors">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column
        prop="logisticsLevel"
        header-align="center"
        align="center"
        label="物流等级"
        width="145px">
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.logisticsLevel"
            :colors="colors">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column
        prop="serviceLevel"
        header-align="center"
        align="center"
        label="服务等级"
        width="145px">
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.serviceLevel"
            :colors="colors">
          </el-rate>
        </template>
      </el-table-column> -->
      <el-table-column
        prop="content"
        header-align="center"
        align="center"
        label="评论内容">
      </el-table-column>
      <el-table-column
        prop="goodsName"
        header-align="center"
        align="center"
        label="商品名"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <a :href="'http://www.yilianbaihui.cn/item_show.html?goodsId=' + scope.row.goodsId">{{scope.row.goodsName}}</a>
        </template>
      </el-table-column>
      <!-- <el-table-column
        prop="commentSort"
        header-align="center"
        align="center"
        label="评论排序">
        <template slot-scope="scope">
          <el-input v-model="scope.row.commentSort" type="number" @change="updatecommentSort(scope.row.commentId, scope.row.commentSort)"/>
        </template>
      </el-table-column> -->
      <el-table-column
        prop="commentImagesStr"
        header-align="center"
        align="center"
        label="评论图片">
        <template slot-scope="scope">
          <span v-if="scope.row.commentImagesStr !== '' && scope.row.commentImagesStr !== null">
            <el-popover
            style="margin-left: 5px;margin-bottom: 5px"
            placement="right"
            title=""
            trigger="hover" v-for="(item, index) in scope.row.commentImagesStr.split(',')" :key="index">
                <img v-if="item !== null" :src="'https://image.yilianbaihui.cn/consumer/' +item" style="max-width: 300px"/>
                <img slot="reference" v-if="item !== null" :src="'https://image.yilianbaihui.cn/consumer/' + item" :alt="item" style="max-height: 30px;max-width: 80px"/>
            </el-popover>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="commentVideosStr"
        header-align="center"
        align="center"
        label="评论视频">
        <template slot-scope="scope">
          <span v-if="scope.row.commentVideosStr !== '' && scope.row.commentVideosStr !== null">
            <el-popover
            style="margin-left: 5px;margin-bottom: 5px"
            placement="right"
            title=""
            trigger="hover" v-for="(item, index) in scope.row.commentVideosStr.split(',')" :key="index">
                <video v-if="item !== null" :src="'https://image.yilianbaihui.cn/consumer/' +item" style="max-width: 300px"/>
                <video slot="reference" v-if="item !== null" :src="'https://image.yilianbaihui.cn/consumer/' + item" :alt="item" style="max-height: 30px;max-width: 80px"/>
            </el-popover>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="auditStatus"
        header-align="center"
        align="center"
        label="审核"
        width="180px">
        <template slot-scope="scope">
          <!-- <el-button size="small" type="warning" icon="check" @click="adopt(scope.row.commentId, 1)" v-if="(scope.row.auditStatus)== 0">通过</el-button>
          <el-button size="small" type="danger" icon="edit" @click="adopt(scope.row.commentId, 2)" v-if="(scope.row.auditStatus)== 0">不通过</el-button> -->
          <el-button size="small" type="warning" icon="check" @click="addOrUpdateHandle(scope.row.commentId, 1,  scope.row.auditReplyCount)" v-if="(scope.row.auditStatus)== 0">审核</el-button>
          <p v-if="scope.row.auditStatus ===  '1'" style="color: blue">审核通过</p>
          <p v-if="scope.row.auditStatus ===  '2'" style="color: red">审核拒绝</p>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.commentId, 2, scope.row.auditReplyCount)">回复</el-button>
          <el-button type="text" size="small" @click="deleteComment(scope.row.commentId)">删除</el-button>
          <!-- <el-button type="text" size="small" @click="commentReply(scope.row.commentId)">评论</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <comment-reply v-if="addOrUpdateVisible" ref="commentReply" @refreshDataList="getDataList"></comment-reply>
    <comment-reply-personal v-if="addOrUpdateVisible" ref="commentReplyPersonal" @refreshDataList="getDataList"></comment-reply-personal>
  </div>
</template>

<script>
  import AddOrUpdate from './comment-reply-personal'
  import commentReply from './comment-reply'
  // import commentReplyPersonal from './comment-reply-personal'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          auditStatus: '',
          startTime: '',
          endTime: '',
          starClass: '',
          commentSrc: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        colors: ['#99A9BF', '#F7BA2A', '#FF9900']
      }
    },
    components: {
      AddOrUpdate,
      commentReply
      // ,
      // commentReplyPersonal
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/good/comment/queryCommentList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'starClass': this.dataForm.starClass,
            'auditStatus': this.dataForm.auditStatus,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime,
            'commentSrc': this.dataForm.commentSrc
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id, type, auditReplyCount) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, type, auditReplyCount)
        })
      },
      commentReply (commentId) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.commentReply.init(commentId)
        })
      },
      commentReplyPersonal (commentId, type) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.commentReplyPersonal.init(commentId, type)
        })
      },
      // 审核操作
      adopt (type) {
        var ids = this.dataListSelections.map(item => {
          return item.commentId
        })
        // if (this.dataForm.auditType === '' && val === '') {
        //   this.$message('请选择审核类型')
        //   return false
        // }
        // if (val === '' && this.dataForm.auditType !== '') {
        //   val = this.dataForm.auditType
        // }
        this.$confirm(`确定进行批量审核操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(`/good/comment/modifyAuditStatusById/${type}`),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      deleteComment (id) {
        let commentIds = []
        commentIds.push(id)
        this.$http({
          url: this.$http.adornUrl(`/good/comment/removeCommentById`),
          method: 'post',
          data: this.$http.adornData(commentIds, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>
